// 导入express
const express = require('express')
// 创建应用对象
const app = express()
// 创建路由规则
// request 是对请求报文的封装
// response 是对响应报文的封装
app.get('/home', (request, response) => {
  // 设置响应
  console.log(request.url, 'request.url')
  console.log(request.path, 'request.path')
  console.log(request.ip, 'request.ip')
  console.log(request.query, 'request.query')
  console.log(request.method, 'request.method')
  console.log(request.params, 'request.params')
  console.log(request.headers, 'request.headers')

  response.send('Hello World')
})

app.post('/login', (request, response) => {
  // 设置响应
  response.send('Hello World login')
})

app.all('/test', (request, response) => {
  // 设置响应
  response.send('所有请求方法都可以访问')
})

app.get('/:id.html', (request, response) => {
  // 设置响应
  console.log(request.params)
  response.send('商品详情')
})

app.all('*', (request, response) => {
  // 设置响应
  response.send('404 Not Found')
})

// 监听端口，启动服务
app.listen(3000, () => {
  console.log('服务已经启动，3000端口监听中...')
})